<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    class main extends CI_Controller {

        public function __construct() {
            parent::__construct();

//            $this->activeLang = $this->lang->mci_current();

//            require_once './application/libraries/urlify.php';
        }

        public function index() {
            $this->home();
        }

        public function home($page = 'home') {

            $this->template->load('site/' . $page);
        }

        function mail_send($to, $message) {

            $from = 'no-reply@apollosvetlosnaparalelnaznanja.com';
            $subject = 'Kontakt sa sajta';

            $headers = "From: $from\r\n";
            $headers .= "Content-type: text/html\r\n";

            return mail($to, $subject, $message, $headers); //0 or 1
        }

        public function submit() {

            if (isset($_POST['name'])) {

                $msg = $this->load->view('parts/email_content', array(), TRUE);

                $success = false;

                $success = $this->mail_send('ikukic@yahoo.com', $msg);
//                $success = mail_send('omoromano.info@gmail.com', $msg);
//                $success = mail_send('omoromana@gmail.com', $msg);
//                $success = mail_send('olivera.kukic@gmail.com', $msg);

                if ($success) {
                    echo json_encode(array('action' => true, 'msg' => 'Uspješno ste poslali poruku! Hvala što ste nas kontaktirali.'));
                } else {
                    echo json_encode(array('action' => false, 'msg' => 'Greška prilikom slanja mejla. Molimo pokušajte ponovo.'));
                }
            } else {
                echo json_encode(array('action' => false, 'msg' => 'Strana nije pronađena.'));
            };
        }

    }

?>